package com.mxnet.chongjin.supoman.activity;

import android.app.Instrumentation;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.mxnet.chongjin.supoman.R;

public class FirmwareUpgradeActivity extends AppCompatActivity implements View.OnClickListener {
    private Context mContext;
    private LinearLayout mLinearLayout, mLinearLayoutNew, mLinearLayoutUpgrade;
    private Button mButton;
    private SharedPreferences mPreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_firmware_upgrade);
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        getWindow().setStatusBarColor(Color.TRANSPARENT);
        mContext = FirmwareUpgradeActivity.this;
        mPreferences = getSharedPreferences("supoman", MODE_PRIVATE);

        initView();
        initData();
    }

    public void initData() {

    }

    public void initView() {
        mLinearLayout = findViewById(R.id.ll_firmware_upgrade);
        mLinearLayout.setOnClickListener(this);

        mLinearLayoutNew = findViewById(R.id.ll_firmware_upgrade_new);

        mLinearLayoutUpgrade = findViewById(R.id.ll_firmware_upgrade_upgrade);

        String versionNo = getIntent().getStringExtra("version");
        if (versionNo.equals(mPreferences.getString("version", "v.1.02"))) {
            mLinearLayoutUpgrade.setVisibility(View.GONE);
        } else {
            mLinearLayoutNew.setVisibility(View.GONE);
        }

        mButton = findViewById(R.id.btn_firmware_upgrade_upgrade);
        mButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_firmware_upgrade:
                new Thread() {
                    public void run() {
                        try {
                            Instrumentation inst = new Instrumentation();
                            inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }.start();
                break;
            case R.id.btn_firmware_upgrade_upgrade:
                //todo 发送更新固件指令
                break;
        }
    }
}
